package zr.com.thread.pool;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;


public class Producer implements Runnable {
    public  final int maxNum = 10000;
    public  final LinkedBlockingDeque<String> QUEUE = new LinkedBlockingDeque<String>(maxNum);

    public  boolean active = true;

    @Override
    public void run() {
        int num = 1;
        while (active) {
            synchronized (this) {
                try {
                    TimeUnit.MICROSECONDS.sleep(1);
                    if (maxNum <= QUEUE.size()) {
                        System.out.println("=========" + Thread.currentThread().getName() + ",清楚队列，size=" + QUEUE.size());
                        num = 1;
                        QUEUE.clear();
                    }
                    QUEUE.offer(Thread.currentThread().getName() + ":" + num);
                } catch (InterruptedException e) {
                    System.out.println(e);
                }
                ++num;
            }
        }
    }
}
